<template>
  <nav class="footer">
    <div class="footer-container">
      <div class="footer-item" :class="{ active: route.path === '/index' }" @click="toIndex">
        <i class="fa fa-home"></i>
        <span>首页</span>
      </div>
      <div class="footer-item" :class="{ active: route.path === '/discover' }" @click="toDiscover">
        <i class="fa fa-compass"></i>
        <span>发现</span>
      </div>
      <div class="footer-item" :class="{ active: route.path === '/orderList' }" @click="toOrderList">
        <i class="fa fa-file-text-o"></i>
        <span>订单</span>
      </div>
      <div class="footer-item" :class="{ active: route.path === '/userInfo' }" @click="toUserInfo">
        <i class="fa fa-user-o"></i>
        <span>我的</span>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

const toIndex = () => {
  if (route.path !== '/index') {
    router.push('/index')
  }
}

const toDiscover = () => {
  // 暂时保留发现页面的功能
  console.log('发现功能开发中...')
}

const toOrderList = () => {
  if (route.path !== '/orderList') {
    router.push('/orderList')
  }
}

const toUserInfo = () => {
  if (route.path !== '/userInfo') {
    router.push('/userInfo')
  }
}
</script>

<style scoped>
.footer {
  width: 100%;
  height: 70px;
  background-color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  border-top: 1px solid #eee;
  z-index: 999;
}

.footer-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: #fff;
}

.footer-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 13px;
  cursor: pointer;
  flex: 1;
  height: 100%;
}

.footer-item i {
  font-size: 26px;
  margin-bottom: 4px;
}

.footer-item span {
  font-size: 13px;
  margin-top: 2px;
}

/* 激活状态 */
.footer-item.active {
  color: #0097FF;
}

/* 点击效果 */
.footer-item:active {
  opacity: 0.8;
}
</style>